package org.school.streaming.net.client.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.school.streaming.net.RequestType;
import org.school.streaming.net.client.Client;

/**
 * @authors Jeffrey Goudzwaard,
 * 			Davin Terrizzi
 * @version	1.0
 * @date	18-4-2013
 */


/**
 * Class representing ActionListener behind TEARDOWN button in Client GUI
 * @author Davin
 *
 */
public class btnTeardownListener implements ActionListener
{
	@Override
	public void actionPerformed( ActionEvent ae )
	{
		System.out.println( "Teardown Button Pressed!" );
		
		// Get Client instance
		Client client = Client.getClient();
		
		// Send TEARDOWN request
		client.sendRequest( RequestType.TEARDOWN );
		
		// Stop timer and exit app nicely if right response is received
		if( client.parseServerResponse() != 200 )
		{
			System.err.println( "Error 100: Invalid Server Response!" );
		}
		else
		{
			client.getTimer().stop();
			System.exit( 0 );
		}
	}
}
